export default function(key, fun, ctx = undefined) {
  let cacheData
  return async function(...args) {
    if (cacheData !== undefined) {
      return cacheData
    }
    const res = fun.apply(ctx, args)
    if (res instanceof Promise) {
      return res.then(res => {
        cacheData = res
        return res
      })
    }
    cacheData = res
    return res
  }
}
